home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / web / fweb / fweb-1.40 / manual / demo4.web < prev    next >
Text File  |  1993-10-29  |  2KB  |  62 lines

  1. @z --- demo4.web ---
  2.  
  3. This file is included in fwebman.tex.
  4.  
  5. Author: J. A. Krommes
  6. Version: 1.23
  7. Date:   May 27, 1992
  8.  
  9. @x-----------------------------------------------------------------------------
  10.  
  11. @n/[-W[]
  12. @* ARRAY PROCESSING.  This example demonstrates two ways of beautifying
  13. array references in \Fortran\ and~C.  Parenthesized references can be
  14. overloaded with the `\.{@@W}'~command, as follows: 
  15.  
  16. @W x . // Replace references to~\Wshort{x} by the macro~\.{\\x}.
  17. @W y .
  18. @W z .
  19.  
  20. @l "\\def\\x(#1){x^{#1}}" // Contravariant index.
  21. @l "\\def\\y(#1){y_{#1}}" // Covariant index.
  22. @l "\\def\\z(#1,#2){z^{#1}{}_{#2}}" // Mixed indices.
  23.  
  24. @ Bracketed array references are activated by the `\.{-W[}'~command.
  25. (In \Fortran\ \FTANGLE\ always automatically replaces brackets by
  26. parentheses.)  One can redefine the \.{\\WARRAY} macro to get special effects.
  27.  
  28. @l "\\let\\WARRAY\\WSUB" /* Subscript bracketed indices.  (\.{\\WSUB}~is
  29. defined in \.{fwebmac.web}.) */
  30.  
  31. @ In the following test, carefully note the difference in type size between
  32. the results of parenthesized subscripts and bracketed ones.  To fully
  33. understand why this occurs, study the definition of the \.{\\WXA}~macro in
  34. \.{fwebmac.web}.
  35.  
  36. @a
  37.     program main
  38.  
  39.     @e
  40. /* Test of overloaded identifiers. */
  41.     x(i)
  42.     y(j)
  43.     z(i,j)
  44.  
  45. /* Bracketed indexing. */
  46.     A[i]
  47.     B[j_par]
  48.     C[index,j_par]
  49.     D[index[j_par+1]]
  50.     E[1+2*i]
  51.  
  52. /* Brackets aren't active inside strings. */
  53.     'a[b]c(d)'
  54.  
  55.     end
  56.  
  57. @c
  58. /* Now, an example from C. */
  59. a[1][2][k]; // In the source, this is ``\.{a[1][2][k]}''.
  60.  
  61. @* INDEX.
  62.